package cn.ld.fj.web.food;

import cn.ld.fj.entity.Food;
import cn.ld.fj.entity.FoodTaste;
import cn.ld.fj.service.food.FoodManager;
import cn.ld.fj.service.food.FoodTasteManager;
import cn.ld.fj.service.food.FoodTypeManager;
import cn.ld.fj.util.RequestParamterUtil;
import net.esoar.modules.orm.Page;
import net.esoar.modules.orm.PropertyFilter;
import net.esoar.modules.utils.web.struts2.Struts2Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zuohao on 2017/8/3.
 */

@Controller
@RequestMapping("foodController")
public class FoodController {

    @Autowired
    private FoodManager foodManager;
    @Autowired
    private FoodTasteManager foodTasteManager;

    private Page<Food> page = new Page<Food>(10);

    @RequestMapping("getFoodTypeList")
    @ResponseBody
    public Object getFoodTypeList(HttpServletRequest request){
        List<PropertyFilter> filters= RequestParamterUtil.getParamter(request);
        if (!page.isOrderBySetted()) {
            page.setOrderBy("id");
            page.setOrder(Page.ASC);
        }
//        resultMap.put("foodList",foodManager.getPage(page,filters));
        return foodManager.getPage(page,filters);
    }

    @RequestMapping("getFoodTasteList")
    @ResponseBody
    public Object getFoodTasteList(){
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("foodTasteList",foodTasteManager.getAll());
        return resultMap;
    }

}
